import selectAction from './searchBtnClick';
import { getPrintCodeByType } from 'utils/netRequest.js';
import { ConstValues, getTenantId } from './../projectIndicators.config';

export default function buttonClick({ key }) {
    let selectRows = this.state.selectRows;
    let currentRow = selectRows.length > 0 ? selectRows[0] : '';
    switch (key) {
        case 'add':
            window.sessionStorage.setItem('pageStatus', 'edit');
            window.sessionStorage.removeItem('pageInfo');
            window.location.href = './resumeworkcard.html';
            break;
        case 'print':
            if (currentRow) {
                getPrintCodeByType({
                    tenantId: getTenantId(),
                    billType: 'FGD',
                    pkBill: currentRow[ConstValues.Primarykey],
                });
            } else {
                this.props.vendorsWarning({ text: '请选择数据!' });
            }
            break;
        case 'attachment':
            if (currentRow) {
                this.ygcUpload.open();
            } else {
                this.props.vendorsWarning({ text: '请选择数据!' });
            }
            break;
        case 'approveDes':
            this.props.approveHistory.initModal({ data: this.state.selectRows[0], primaryKey: ConstValues.Primarykey });
            break;
        case 'refresh':
            let { selectedS } = this.props.search.getSearchData();
            selectAction.call(this, selectedS, { type: 'refresh' });
            break;
        default:
            break;
    }
}
